package com.wj.advice;

import com.wj.vo.CommonResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 * 全局异常处理
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionAdvice {

    @ExceptionHandler(value = Exception.class)
    public CommonResponse<String> handleCommerceException(HttpServletRequest request, Exception e){
        CommonResponse<String> response = new CommonResponse<>(-1, "business error");
         response.setData(e.getMessage());
         log.error("service has error: [{}]",e.getMessage(),e);
         return response;
    }
}
